package com.onlineclass.classserver.service.impl;

import com.onlineclass.classserver.constant.Restult;
import com.onlineclass.classserver.mapper.CourseTeacherMapper;
import com.onlineclass.classserver.service.ICouseTeacherService;
import com.onlineclassbackstage.beans.Course;
import com.onlineclassbackstage.beans.User;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class CourseTeacherService implements ICouseTeacherService {

    @Autowired
    CourseTeacherMapper mapper;

    @Override
    public List<Course> selectCoursesByTeacher(User user) {
//        System.out.println(session.getId());
        int uid = user.getId();

        return mapper.selectCourseTeacher(uid);
    }

    @Override
    public int insertCourseByTeacher(Course course,User user) {
        int uid = user.getId();
        if (mapper.insertCourse(course) >= Restult.getRight()){
            if (mapper.insertCourseByTeacher(uid,course) >= Restult.getRight()){
                return Restult.getRight();
            } else{
                return Restult.getError();
            }
        } else {
            return Restult.getError();
        }

    }
}
